require "Common/define"
require "Logic/Config"
require "Common/functions"

RedDotsActivitySidebarHandler = {};
local this = RedDotsActivitySidebarHandler;

function RedDotsActivitySidebarHandler.init()
    CloseEvent(Config.EventType.Fresh_Active, this.update);
    CloseEvent(Config.EventType.Fresh_SevenDay, this.update);
    CloseEvent(Config.EventType.Fresh_TaskInfo, this.update);
    CloseEvent(Config.EventType.Res_TaskInfo_Get, this.update);
    CloseEvent(Config.EventType.Fresh_NewStage, this.update);
    ListenEvent(Config.EventType.Fresh_NewStage, this.update);
    ListenEvent(Config.EventType.Fresh_TaskInfo, this.update);
    ListenEvent(Config.EventType.Res_TaskInfo_Get, this.update);
    ListenEvent(Config.EventType.Fresh_SevenDay, this.update);
    ListenEvent(Config.EventType.Fresh_Active, this.update);
    return this;
end

--参数1：指定活动Id，nil代表检查侧边栏活动
---活动红点
function RedDotsActivitySidebarHandler.getFlag(...)
    local flag = Config.RedDotsFlagState.None;
    local tabId = ...;
    local tableData = {};
    if tabId == nil then
        tableData = logicMgr.ActiveManager.getActiveEntranceDataListByType(EnumConst.ActiveShowType.LeftSidebar);
    else
        table.insert(tableData, logicMgr.ActiveManager.getActiveServerDataList(tabId));
    end
    for k, v in pairs(tableData) do
        local itemTableData, serverData = logicMgr.ActiveManager.getActiveData(v.activeId);
        if serverData ~= nil then
            if serverData.redDots then
                flag = Config.RedDotsFlagState.Needful;
                break;
            end
        end
    end
    return flag;
end

function RedDotsActivitySidebarHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.ActivitySidebar);
end